//
//  File.swift
//  FMDBDemo
//
//  Created by chenxinju on 16/5/18.
//  Copyright © 2016年 Innovation. All rights reserved.
//

import UIKit
import FMDB


class FMDBManager {

    static let shareInstance:FMDBManager = FMDBManager()
    
    //创建一个数据库
    let db:FMDatabase
 
  private  init() {
    
       let path = NSSearchPathForDirectoriesInDomains( .DocumentDirectory, .UserDomainMask, true).last! as NSString
      print(path)
    
       //拼接路径
     let dbpath = path.stringByAppendingPathComponent("demo.db")
    
     //创建数据库
     db = FMDatabase(path: dbpath)
    
     //打开数据库
               if db.open() {
                  print("成功打开数据库")
               }else {
                
                print("打开失败")
                return
               }
    
         createTable()
    
    }
    
    //创建一个表格
    private func createTable() {
    let sql = "CREATE TABLE IF NOT EXISTS 'T_Person' ('person_id' integer NOT NULL PRIMARY KEY AUTOINCREMENT,'name' tet,'score' integer,'sex' integer)"

    //执行sql语句
        if db.executeStatements(sql) {
        print("创建表格成功")
       
        }else {
        
            print("创建表格失败")
        }

    }

}
